import 'dart:math';

class Food {
  Point<int> position;
  final int gridSize;
  
  Food(this.gridSize) : position = Point(0, 0) {
    reset([]);
  }
  
  void reset(List<Point<int>> snakeBody) {
    final random = Random();
    Point<int> newPosition;
    
    do {
      newPosition = Point(
        random.nextInt(gridSize),
        random.nextInt(gridSize),
      );
    } while (snakeBody.any((segment) => 
        segment.x == newPosition.x && segment.y == newPosition.y));
    
    position = newPosition;
  }
}